package cn.edu.usst.cs.captcha_nxy;

import java.io.IOException;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.annotation.WebServlet;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        String userCode = request.getParameter("code");
        String hiddenCode = request.getParameter("hiddenVerifyCode");

        String message;
        if (userCode != null && userCode.equalsIgnoreCase(hiddenCode)) {
            message = "验证成功";
        } else {
            message = "验证失败，请重新输入";
        }

        request.setAttribute("message", message);
        RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
        dispatcher.forward(request, response);
    }

    public void destroy() {
    }
}
